  // 获取用户信息
fn()
function fn(){

axios.get('/my/userinfo', {
  // 请求头headers
  // headers: {
  //   Authorization: localStorage.getItem('token')
  // },
})
  .then(({ data: { data, status, message } }) => {

    // console.log(res)
    // if (status === 1 && message === '身份认证失败！') {
    //   location.href = '/login.html'
    // }
    const { nickname, username, user_pic } = data
    let name = nickname || username
    // console.log(name)
    if (user_pic) {
      $('.avatar').attr('src', user_pic).show()
      $('.text-avatar-box').hide()
    } else {
      $('.text-avatar-box').show()
      $('.text-avatar').text(name[0].toUpperCase())
      $('.avatar').hide()
    }

    // 欢迎
    $("#welcome").text(`欢迎 ${name} `)
  })
}

// 退出功能
let layer = layui.layer
$('#btnLogout').on('click', () => {
  //弹框
  layer.confirm('确认退出登录吗',
    { icon: 3, title: '提示' },
    function (index) {
      //do something
      // 该回调函数点击确认的时候执行
      // console.log(index)
      localStorage.removeItem('token')
      location.href = '/login.html'
      // 关闭弹出代码
      layer.close(index)
    })

})